﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using GrammarGenericSolver.Model;

namespace GrammarGenericSolver.Test
{
    [TestClass]
    public class SolverTest
    {
        private string grammar01path = "Input/grammar01.txt";
        private string grammar02path = "Input/grammar02.txt";
        private string grammar03path = "Input/grammar03.txt";

        [TestInitialize]
        public void TestInitialize()
        {
        }

        [TestMethod]
        public void Grammar01Test()
        {
            Grammar grammar01 = new Grammar(grammar01path);

            //Testes esperando verdadeiro
            Assert.AreEqual(true, grammar01.VerifySentence("a"), "Cadeia 'a' deu erro.");
            Assert.AreEqual(true, grammar01.VerifySentence("b"), "Cadeia 'b' deu erro.");
            Assert.AreEqual(true, grammar01.VerifySentence("c"), "Cadeia 'c' deu erro.");
            Assert.AreEqual(true, grammar01.VerifySentence("0"), "Cadeia '0' deu erro.");
            Assert.AreEqual(true, grammar01.VerifySentence("1"), "Cadeia '1' deu erro.");
            Assert.AreEqual(true, grammar01.VerifySentence("2"), "Cadeia '2' deu erro.");
            Assert.AreEqual(true, grammar01.VerifySentence("3"), "Cadeia '3' deu erro.");

            //Testes esperando falso
            Assert.AreEqual(false, grammar01.VerifySentence("aa"), "Cadeia 'aa' deu erro.");
            Assert.AreEqual(false, grammar01.VerifySentence("ab"), "Cadeia 'ab' deu erro.");
            Assert.AreEqual(false, grammar01.VerifySentence("00"), "Cadeia '00' deu erro.");
            Assert.AreEqual(false, grammar01.VerifySentence("4"), "Cadeia '4' deu erro.");
            Assert.AreEqual(false, grammar01.VerifySentence("e"), "Cadeia 'e' deu erro.");
        }

        [TestMethod]
        public void Grammar02Test()
        {
            Grammar grammar02 = new Grammar(grammar02path);

            //Testes esperando verdadeiro
            Assert.AreEqual(true, grammar02.VerifySentence("a"), "Cadeia 'a' deu erro.");
            Assert.AreEqual(true, grammar02.VerifySentence("ab"), "Cadeia 'ab' deu erro.");
            Assert.AreEqual(true, grammar02.VerifySentence("a0.1"), "Cadeia 'a0.1' deu erro.");
            Assert.AreEqual(true, grammar02.VerifySentence("c"), "Cadeia 'c' deu erro.");
            Assert.AreEqual(true, grammar02.VerifySentence("a9.9"), "Cadeia 'a9.9' deu erro.");

            //Testes esperando falso
            Assert.AreEqual(false, grammar02.VerifySentence("0"), "Cadeia '0' deu erro.");
            Assert.AreEqual(false, grammar02.VerifySentence("b"), "Cadeia 'b' deu erro.");
            Assert.AreEqual(false, grammar02.VerifySentence("a0"), "Cadeia 'a0' deu erro.");
            Assert.AreEqual(false, grammar02.VerifySentence("a."), "Cadeia 'a.' deu erro.");
            Assert.AreEqual(false, grammar02.VerifySentence("."), "Cadeia '.' deu erro.");
        }

        [TestMethod]
        public void Grammar03Test()
        {
            Grammar grammar03 = new Grammar(grammar03path);

            //Testes esperando verdadeiro
            Assert.AreEqual(true, grammar03.VerifySentence("aaa"), "Cadeia 'aaa' deu erro.");
            Assert.AreEqual(true, grammar03.VerifySentence("bab"), "Cadeia 'bab' deu erro.");
            Assert.AreEqual(true, grammar03.VerifySentence("bba"), "Cadeia 'bba' deu erro.");
            Assert.AreEqual(true, grammar03.VerifySentence("bbbaaa"), "Cadeia 'bbbaaa' deu erro.");
            Assert.AreEqual(true, grammar03.VerifySentence("aaabbbaaa"), "Cadeia 'aaabbbaaa' deu erro.");

            //Testes esperando falso
            Assert.AreEqual(false, grammar03.VerifySentence("a"), "Cadeia 'a' deu erro.");
            Assert.AreEqual(false, grammar03.VerifySentence("aa"), "Cadeia 'aa' deu erro.");
            Assert.AreEqual(false, grammar03.VerifySentence("c"), "Cadeia 'c' deu erro.");
            Assert.AreEqual(false, grammar03.VerifySentence("ba."), "Cadeia 'ba.' deu erro.");
            Assert.AreEqual(false, grammar03.VerifySentence("babb"), "Cadeia 'babb' deu erro.");
        }
    }
}
